package com.yonyou.cyxdms.sysAuth.service.controller.carfaccompanymaintenance;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yonyou.cyx.framework.controller.base.BaseController;
import com.yonyou.cyxdms.basedata.client.domains.vo.RegionVO;
import com.yonyou.cyxdms.basedata.client.service.basedata.BaseCommonRegionService;
import com.yonyou.cyxdms.sysAuth.service.dto.carfaccompanymaintenance.CarFacCompanyMaintenanceTreeDTO;
import com.yonyou.cyxdms.sysAuth.service.service.carfaccompanymaintenance.CarFacCompanyMaintenanceService;
import com.yonyou.cyxdms.sysAuth.service.vo.carfaccompanymaintenance.DealerBasicinfoVO;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 车厂公司维护控制类
 * 
 * @author lxj
 * @date 2018年12月13日
 */

@RestController
@RequestMapping("/car/factory")
public class CarFacCompanyMaintenanceController extends BaseController {
    
    @Autowired
    private CarFacCompanyMaintenanceService carFacCompanyMaintenanceService;


    @Autowired
    private BaseCommonRegionService baseCommonRegionService;

    /**
     * 车厂公司维护控制类  DealerBasicinfoVO
     *
     * @author dengqiang
     * @since 2019/7/18
     */
    @ApiOperation(value="车厂公司维护控制类分页查询")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "userId", name = "userId", required = true, dataType = "string", paramType = "header")
    })
    @GetMapping
    public IPage<DealerBasicinfoVO> queryDealerBasicinfo(@ApiParam(name = "pageNum", value = "当前页") @RequestParam("pageNum") Long current
            , @ApiParam(name = "limit", value = "分页大小") @RequestParam("limit") Long size, @RequestParam Map<String, Object> param) {
        Page<DealerBasicinfoVO> page = new Page(current, size);
        return carFacCompanyMaintenanceService.queryDealerBasicinfo(page,param);
    }


    /**
     * 车厂公司维护控制类新增
     *
     * @author dengqiang
     * @since 2019/7/22
     */
    @PostMapping
    @ResponseBody
    public Integer addOrg(@RequestBody CarFacCompanyMaintenanceTreeDTO carFacCompanyMaintenanceTreeDTO) {
        return carFacCompanyMaintenanceService.addOrg(carFacCompanyMaintenanceTreeDTO);
    }


    /**
     * 车厂公司维护控制类修改
     *
     * @author dengqiang
     * @since 2019/7/22
     */
    @PutMapping(value = "/{id}")
    @ResponseBody
    public void modifyOrg(@PathVariable("id") String ids,@RequestBody CarFacCompanyMaintenanceTreeDTO orgDto) {
        carFacCompanyMaintenanceService.modifyComOrg(ids, orgDto);
    }

    @ApiOperation(value = "测试")
    @GetMapping(value = "/feignRegion")
    @ResponseBody
    public List<RegionVO> feignRegion() {
        List<RegionVO> regionVOList = new ArrayList<>();
        List<com.yonyou.cyxdms.basedata.client.domains.vo.RegionVO> regionvos = baseCommonRegionService.listAllData();
        for (com.yonyou.cyxdms.basedata.client.domains.vo.RegionVO regionVO : regionvos) {
            RegionVO region = new RegionVO();
            BeanUtils.copyProperties(regionVO, region);
            regionVOList.add(region);
        }
        return regionVOList;
    }



}
